import lombok.SneakyThrows;
import org.apache.catalina.startup.HostConfig;
import org.apache.catalina.startup.Tomcat;
import org.apache.catalina.startup.VersionLoggerListener;

import java.io.File;

/**
 * @author 80241997 - Liming.Shi
 */

public class DemoTomcat {
    @SneakyThrows
    public static void main(String[] args) {
        File catalinaHome = new File("/home/ubuntu/erp/tomcat"); // folder must exist
        Tomcat tomcat = new Tomcat();
        tomcat.setPort(8080); // HTTP port
        tomcat.setBaseDir(catalinaHome.getAbsolutePath());
        tomcat.getServer().addLifecycleListener(new VersionLoggerListener()); // nice to have

// This magic line makes Tomcat look for WAR files in catalinaHome/webapps
// and automatically deploy them
        tomcat.getHost().addLifecycleListener(new HostConfig());

// Manually add WAR archives to deploy.
// This allows to define the order in which the apps are discovered
// plus the context path.
        File war = new File("/home/ubuntu/erp/rebuild/target/rebuild.war");
        tomcat.addWebapp("/rebuild", war.getAbsolutePath());

        tomcat.start();

    }
}
